package edu.zut.cs.software.example.space.dao;

import java.util.List;


import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import edu.zut.cs.software.example.dao.GenericDao;
import edu.zut.cs.software.example.market.domain.Product;
import edu.zut.cs.software.example.space.domain.Space;




/**
 * 
 * @author ma jiang tao
 *
 */

@Repository
public interface SpaceDao extends GenericDao<Space, Long> {
	
	
	/**
	 * Get all the study notes
	 * 
	 * @param studentid
	 * @param pagenum
	 * @param pageSize
	 * @return
	 */
	@Query(value = "  SELECT * FROM `example`.`t_space` WHERE `studentid`= ?1 LIMIT ?2,?3 ", nativeQuery = true)
	public List<Space> findByStudentId(@Param("studentid")Long studentid,@Param("pagenum") int pagenum,@Param("pageSize") int pageSize);
	
	
	/**
	 * 
	 * @param studentid
	 * @return
	 */
	@Query(value = "  SELECT count(*) FROM `example`.`t_space` WHERE `studentid` = ?1 ", nativeQuery = true)
	public int getSpaceByStudentIdCounts(@Param("studentid") Long studentid);
	
	/**
	 *  
	 * 
	 * @param message
	 * @return
	 */
	@Query(value = "  SELECT count(*) FROM `example`.`t_space` WHERE `message`LIKE CONCAT('%',?1,'%') ", nativeQuery = true)
	public int getSpaceBymessageCounts(@Param("message") String message);
	
   
	/**
	 * 
     * 
     * @param messagemessage
     * @param pagenum
     * @param pageSize
     * @return
     */
	@Query(value = "  SELECT * FROM `example`.`t_space` WHERE `message` LIKE CONCAT('%',?1,'%')  LIMIT ?2,?3 ", nativeQuery = true)
	public List<Space> findBymessage(@Param("message")String message,@Param("pagenum") int pagenum,@Param("pageSize") int pageSize);
    
	/**
	 * 
	 * @param id
	 * @return
	 */
	@Query(value = " SELECT * FROM `example`.`t_space` WHERE `ID`=?1 ", nativeQuery = true)
	public Space getUpdateSpace(@Param("id") int id);
	/**
	 * Query learning notes according to id todeleye
	 * 
	 * @param id
	 * @return
	 */
	@Modifying
	@Transactional
	@Query(value = "  DELETE  FROM `example`.`t_space` WHERE `ID`=?1 ", nativeQuery = true)
	public int deleteById(@Param("id")int id);
    
	/**
	 * 
	 * @param dynamic
	 * @param message
	 * @param id
	 * @return
	 */
	@Query(value = "  UPDATE `example`.`t_space` SET dynamic=:dynamic , message=:message WHERE ID=:id  ", nativeQuery = true)
	@Modifying
	@Transactional
	public int editspace(@Param("dynamic") String dynamic,@Param("message")String message,@Param("id")Long id);

	
	


}
